import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pornhub_app/model/community/community_date_model.dart';
import 'package:pornhub_app/model/community/community_model.dart';
import 'package:pornhub_app/model/message/mine_message_model.dart';

import '../../../../components/base_refresh/base_refresh_page_counter.dart';
import '../../../../http/api/api.dart';

class MineMessagePageController extends GetxController
    with BaseRefreshPageCounter {
  EasyRefreshController refreshController = EasyRefreshController();

  final PagingController<int, MineMessageModel> pagingControllers =
      PagingController(firstPageKey: 1);

  onRefresh() async {
    resetPage();
    return await getMineMessageList(isRefresh: true);
  }

  onLoad() async {
    incPage();
    return await getMineMessageList();
  }

  getMineMessageList({bool isRefresh = false}) async {
    try {
      if (isRefresh) {
        pagingControllers.refresh();
      }
      final response = await Api.getMineMessageList(page: page, pageSize: 20);
      if (response!.isNotEmpty) {
        pagingControllers.appendPage(response, page);
      } else {
        pagingControllers.appendLastPage([]);
      }
    } catch (_) {}
  }
}
